﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using BRM.Business;
using System.IO;
namespace BRM.GUI
{
    public partial class ProgressBar : DevExpress.XtraEditors.XtraForm
    {
        int c;
        public ProgressBar(int inumber)
        {
            InitializeComponent();
            c = inumber;
            progressBarControl1.Properties.Maximum = c;
            progressBarControl1.Position = 0;
        }

        private void XtraForm2_Load(object sender, EventArgs e)
        {
            BackupController.DoProcessHandler += new BackupController.DoProcess(ModuleManager_DoProcessHandler);
            RestoreController.DoProcessHandler += new RestoreController.DoProcess(ModuleManager_DoProcessHandler);
        }
        public delegate void SetFileNameHandle(string name);
        public void SetText(string name)
        {
            if (labelControl1.InvokeRequired)
            {
                SetFileNameHandle f = new SetFileNameHandle(SetText);
                this.Invoke(f, new string[] { name });
            }
            else
            {
                labelControl1.Text = name;
                if (c >= 0)
                {
                    c--;
                    progressBarControl1.Position += 1;
                    if (progressBarControl1.Position == progressBarControl1.Properties.Maximum)
                    {
                        simpleButton1.Enabled = true;
                    }
                }
            }
        }

        void ModuleManager_DoProcessHandler(string fileName)
        {
            SetText(fileName);
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}